home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *
- * NSSDC/CDF Header file for CDF library.
- *
- * Version 3.0, 24-Feb-92, ST Systems (STX)
- *
- * Modification history:
- *
- * V1.0 22-Jan-91, R Kulkarni/J Love Original version (for CDF V2.0).
- *
- * V2.0 3-Jun-91, J Love Renamed (was cdf_internal.h).
- * Modified for CDF V2.1, namely the
- * moving of constant macros to "cdf.h"
- * for the INTERNAL interface and the
- * single/multi file option. Renamed
- * some symbols for clarity.
- * V2.1 24-Jun-91, J Love Fixed for SGi port.
- * V2.2 8-Aug-91, J Love Added 'Eof' (feof). Added some
- * miscellaneous macro definitions.
- * Renamed (was cdflib.h). Added support
- * for Cray/UNICOS. Added 'Exit' and
- * 'ExitBAD'. Added VIO_FOR_STREAM.
- * Functions in VIO were renamed to avoid
- * collisions on SGi/IRIX.
- * V3.0 24-Feb-92, J Love IBM PC & HP-UX port. CDF V2.2.
- *
- ******************************************************************************/
-
- #if !defined(___cdflib_h___)
- #define ___cdflib_h___
-
- /*****************************************************************************
- * Include files.
- *****************************************************************************/
-
- #include "cdfdist.h"
-
- /*****************************************************************************
- * Typedefs for fields.
- *****************************************************************************/
-
- typedef long Int32;
-
- /*****************************************************************************
- * Magic numbers.
- *****************************************************************************/
-
- #define V1_MAGIC_NUMBER_flip 0x0F000000 /* What a V1 magic number looks
- like when the bytes are
- flipped. The bytes will be
- flipped on a VAX because the
- longword was assumed to be in
- network order and then flipped
- to VAX order. The bytes will
- be flipped on a Sun, Cray,
- MIPSEB, and MIPSEL because the
- longword was assumed to already
- be in network order (the same
- as those machines) but the byte
- order in memory is reversed
- from that of a VAX (where all
- V1 CDFs were created). */
-
- #define V2_MAGIC_NUMBER 0x0000FFFF
-
- /*****************************************************************************
- * Optimization/configuration.
- *****************************************************************************/
-
- #define GUESS_V1_VECTOR_SIZES 0 /* When TRUE (1), the number of records
- in CDF V1 vector (variable) files
- will be guessed at. */
-
- #define FULL_ERROR_CHECKING 1 /* When TRUE (1), all error checking
- code will be compiled into the
- library. */
-
- #define INCLUDE_STATUS_TEXT 1 /* When TRUE (1), explanation text for
- status codes is compiled into the
- library. */
-
- /*****************************************************************************
- * Reserved values.
- *****************************************************************************/
-
- #define RESERVED_CDFID (CDFid) (-1) /* indicates that a CDFid
- hasn't been selected yet */
-
- #define RESERVED_CDFSTATUS (CDFstatus) (-1) /* indicates that a CDFstatus
- hasn't been selected yet */
-
- #define RESERVED_ENTRYNUM (long) (-1) /* indicates that an entry
- number hasn't been selected
- yet */
-
- /*****************************************************************************
- * CDF V1.1 parameters.
- *****************************************************************************/
-
- #define V1_DATATYPE_STRING_LEN 8
- #define V1_CDR_OFFSET 4 /* aka, Header record */
- #define V1_GDR_OFFSET 1576
- #define V1_FIRST_VDR_OFFSET 1728
- #define V1_MAX_DIMS 10
- #define V1_VAR_NAME_LEN 8
- #define V1_ATTR_NAME_LEN 8
-
- #define CDFV1_DATA_TYPE_LEN 8
- #define CDFV1_ATTR_NAME_LEN 8
- #define CDFV1_VAR_NAME_LEN 8
- #define CDFV1_CDF_NAME_LEN 100
-
- #define CDFV1_OK 0
- #define CDFV1_DEFAULT_RCODE 1
- #define CDFV1_NO_SUCH_VAR 45
- #define CDFV1_NO_SUCH_ATTR 30
- #define CDFV1_NO_SUCH_ATTR_ENTRY 25
-
- #define TWO_BLANKS 8224 /* "lowest" 2-character attribute or
- variable name possible (although
- nobody in their right mind would
- use it) */
-
- /*****************************************************************************
- * CDF V2.0+ parameters.
- *****************************************************************************/
-
- #define V2_MAGIC_OFFSET 0
- #define V2_CDR_OFFSET 8
-
- #define N_VXR_ENTRIES 10
-
- #if defined(__IBMPC__)
- #define nCACHE_BUFFERs_CDF 10
- #else
- #define nCACHE_BUFFERs_CDF 750
- #endif
-
- #define nCACHE_BUFFERs_CDH 2
- #define nCACHE_BUFFERs_Vnn 10
-
- #define MIN_nEXTEND_BYTES_single 512
- #define MIN_nEXTEND_RECS_single 1
-
- #define MIN_nEXTEND_RECS_multi 1 /* don't set this greater than 1
- unless the algorithm to extend
- variable files is changed - extra
- writes to the files may result */
-
- /*****************************************************************************
- * Operating system dependent definitions.
- *****************************************************************************/
-
- #if defined(vms)
- #define VIO_FOR_STREAM 1
- #endif
-
- #if defined(unix) | defined(__MSDOS__)
- #define VIO_FOR_STREAM 1
- #endif
-
- #if VIO_FOR_STREAM
- #include "vio.h"
- #define File VFILE
- #define Open(filespec,a_mode,n_buffers) Vopen(filespec,a_mode,n_buffers)
- #define Seek(fp,offset,direction) Vseek(fp,offset,direction)
- #define Read(buffer,itemsize,numitems,fp) Vread(buffer,itemsize,numitems,fp)
- #define Write(buffer,itemsize,numitems,fp) Vwrite(buffer,itemsize,numitems,fp)
- #define Tell(fp) Vtell(fp)
- #define Eof(fp) Veof(fp)
- #define Close(fp) Vclose(fp)
- #else
- #define File FILE
- #define Open(filespec,a_mode) fopen(filespec,a_mode)
- #define Seek(fp,offset,direction) fseek(fp,offset,direction)
- #define Read(buffer,itemsize,numitems,fp) fread(buffer,itemsize,numitems,fp)
- #define Write(buffer,itemsize,numitems,fp) fwrite(buffer,itemsize,numitems,fp)
- #define Tell(fp) ftell(fp)
- #define Eof(fp) feof(fp)
- #define Close(fp) fclose(fp)
- #endif
-
- /*****************************************************************************
- * Machine dependent definitions.
- *****************************************************************************/
-
- #if defined(sun) | defined(MIPSEB) | defined(IBMRS) | defined(HP)
- #define DecodeBuffer(encoding,dataType,numElements,buffer) {} /* null */
- #endif
-
- #if defined(vax) | defined(MIPSEL) | defined(__IBMPC__)
- #define DecodeBuffer(encoding,dataType,numElements,buffer) \
- if (encoding == NETWORK_ENCODING) xdr_decode (dataType, numElements, buffer)
- #endif
-
- /*****************************************************************************/
-
- #if defined(sun) | defined(MIPSEB) | defined(IBMRS) | defined(HP)
- #define getint32(fp,x) Read(&x,4,1,fp)
- #define putint32(fp,x) Write(&x,4,1,fp)
- #endif
-
- #if defined(vax) | defined(MIPSEL) | defined(__IBMPC__)
- #define getint32(fp,x) { \
- long tmp; \
- Read(&tmp,4,1,fp); \
- x = ntohl(tmp); \
- }
- #define putint32(fp,x) { \
- long tmp; \
- tmp = htonl(x); \
- Write(&tmp,4,1,fp); \
- }
- #endif
-
- /*****************************************************************************/
-
- #if defined(vax)
- #define getint32H(fp,x) Read(&x,4,1,fp)
- #define putint32H(fp,x) Write(&x,4,1,fp)
- #endif
-
- /*****************************************************************************
- * Miscellaneous macros.
- *****************************************************************************/
-
- #define getbytes(len,x,fp) Read(x,1,len,fp)
- #define putbytes(len,x,fp) Write(x,1,len,fp)
-
- /*****************************************************************************
- * Internal CDF/variable status codes.
- *****************************************************************************/
-
- #define CDF_CLOSED (long) 501
- #define CDF_READ_ONLY (long) 502
- #define CDF_READ_WRITE (long) 503
- #define VAR_CLOSED (long) 504
- #define VAR_OPENED (long) 505
- #define NO_VAR_FILE (long) 506
-
- /*****************************************************************************
- * Variable flag bit positions (bit 0 is Least Significant Bit). For flag
- * bits in the VDR.
- *****************************************************************************/
-
- #define VAR_RECVARY_BIT 0 /* record variance:
- set = VARY,
- clear = NOVARY */
- #define VAR_FILLVALUE_BIT 1 /* fill value:
- set = specified,
- clear = not specified (use
- default) */
-
- /*****************************************************************************
- * CDF flag bit positions (bit 0 is Least Significant Bit). For flag bits in
- * the CDR.
- *****************************************************************************/
-
- #define CDF_MAJORITY_BIT 0 /* majority: set = row major,
- clear = column major */
- #define CDF_FORMAT_BIT 1 /* format: set = single file,
- clear = multi file */
-
- /*****************************************************************************
- * Record types.
- *****************************************************************************/
-
- #define UNUSED_ (Int32) (-1) /* no longer used (original record moved) */
-
- #define CDR_ (Int32) 1 /* CDF Descriptor Record */
- #define GDR_ (Int32) 2 /* Global Descriptor Record */
- #define VDR_ (Int32) 3 /* Variable Descriptor Record */
- #define ADR_ (Int32) 4 /* Attribute Descriptor Record */
- #define AEDR_ (Int32) 5 /* Attribute Entry Descriptor Record */
- #define VXR_ (Int32) 6 /* Variable indeX Record */
- #define VVR_ (Int32) 7 /* Variable Values Record */
-
- /*****************************************************************************
- * Base record sizes (bytes).
- *****************************************************************************/
-
- #define CDR_BASE_SIZE 48
- #define GDR_BASE_SIZE 60
- #define VDR_BASE_SIZE 64
- #define VXR_BASE_SIZE 20
- #define VVR_BASE_SIZE 8
- #define ADR_BASE_SIZE 52
- #define AEDR_BASE_SIZE 48
-
- /*****************************************************************************
- * CDR structure.
- *****************************************************************************/
-
- struct CDRstruct {
- Int32 RecordSize; /* Size of record (bytes) */
- Int32 RecordType; /* Type of record (ie. CDR) */
- Int32 GDRoffset; /* File offset to GDR (bytes) */
- Int32 Version; /* CDF Version Number */
- Int32 Release; /* CDF Release Number */
- Int32 Encoding; /* Encoding of CDF File */
- Int32 Flags; /* Flags: bit 0 -> majority
- if set, ROW major
- if clear, COLUMN major
- bit 1 -> format
- if set, SINGLE file
- if clear, MULTI file */
- Int32 rfuA; /* reserved for future use (value = 0) */
- Int32 rfuB; /* reserved for future use (value = 0) */
- Int32 Increment; /* CDF Increment Number (Vversion.release.increment),
- always 0 for V2.0 CDFs */
- Int32 rfuD; /* reserved for future use (value = -1) */
- Int32 rfuE; /* reserved for future use (value = -1) */
- char copyright[CDF_COPYRIGHT_LEN];
- /* copyright message for CDF */
- };
-
- /*****************************************************************************
- * GDR structure.
- *
- * Note(s):
- * The Eof field was not maintained for V2.0 CDFs (it will contain a random
- * value). When a V2.0 CDF is opened, the end-of-file will be determined and
- * placed in this field (in memory, not on disk yet). If the V2.0 CDF is
- * modified (access changed to READ/WRITE), the release will be changed to 1
- * and this field will contain the correct value (when written to disk). The
- * V2.0 CDF will have been automatically converted to a V2.1 CDF.
- *
- *****************************************************************************/
-
- struct GDRstruct {
- Int32 RecordSize; /* Size of current record (bytes) */
- Int32 RecordType; /* Type of record (ie. GDR) */
- Int32 VDRhead; /* File offset to first VDR (bytes) */
- Int32 garbage1; /* value is undefined (random) */
- Int32 ADRhead; /* File offset to first ADR (bytes) */
- Int32 eof; /* If V2.0 CDF, value is undefined (random).
- If V2.1 CDF, end-of-file (byte offset). */
- Int32 NumVar; /* Number of Variables */
- Int32 NumAttr; /* Number of Attributes */
- Int32 MaxRec; /* Maximum record number in CDF */
- Int32 NumDims; /* Number of CDF dimensions */
- Int32 rfuA; /* reserved for future use (value = 0) */
- Int32 rfuB; /* reserved for future use (value = 0) */
- Int32 rfuC; /* reserved for future use (value = 0) */
- Int32 rfuD; /* reserved for future use (value = -1) */
- Int32 rfuE; /* reserved for future use (value = -1) */
- Int32 *DimSizes; /* Size of each dimension */
- };
-
- /*****************************************************************************
- * VDR structure.
- *****************************************************************************/
-
- struct VDRstruct {
- Int32 RecordSize; /* Size of current record (bytes) */
- Int32 RecordType; /* Type of record (ie. VDR) */
- Int32 VDRnext; /* File offset to next VDR (bytes) */
- Int32 DataType; /* DataType of Variable */
- Int32 MaxRec; /* Maximum record number for variable */
- Int32 VXRhead; /* File offset to first VXR (bytes). Value will be
- 0 if MULTI_FILE format */
- Int32 VXRtail; /* File offset to last VXR (bytes). Value will be 0
- if MULTI_FILE format */
- Int32 Flags; /* Flags: bit 0 -> record variance
- if set, VARY
- if clear, NOVARY */
- Int32 rfuA; /* reserved for future use (value = 0) */
- Int32 rfuB; /* reserved for future use (value = 0) */
- Int32 rfuC; /* reserved for future use (value = -1) */
- Int32 REFvarNum; /* Number of referenced variable (If -1, use
- variable's number in this CDF. If -1, then
- REFfilename should be null.) */
- char REFfilename[CDF_VAR_FILE_NAME_LEN+1];
- /* Name of referenced variable file (If null, use
- this CDF's file name. If null, then REFvarNum
- should be -1.) */
- Int32 NumElem; /* Number of elements of DataType (should be 1 if not
- CDF_CHAR or CDF_UCHAR) */
- Int32 Num; /* Variable number */
- Int32 rfuD; /* reserved for future use (value = -1) */
- Int32 NextendRecs; /* number of records to extend variable when new
- allocations are necessary (if 0, use default) */
- char Name[CDF_VAR_NAME_LEN+1];
- /* Variable name */
- Int32 *DimVarys; /* dimension variances */
- void *FillValue; /* fill value for extending variable (present only if
- VAR_FILLVALUE_BIT set in "Flags") */
- };
-
- /*****************************************************************************
- * VXR structure.
- *****************************************************************************/
-
- struct VXRstruct {
- Int32 RecordSize; /* Size of current record (bytes) */
- Int32 RecordType; /* Type of record (ie. VXR) */
- Int32 VXRnext; /* File offset to next VXR (bytes) */
- Int32 Nentries; /* Number of index entries (entries not being used
- contain -1 in each field) */
- Int32 NusedEntries; /* Number of index entries actually used */
- Int32 *FirstRec; /* First record number in VVR */
- Int32 *LastRec; /* Last record number in VVR */
- Int32 *VVRoffset; /* File offset to VVR (bytes) */
- };
-
- /*****************************************************************************
- * VVR structure.
- *****************************************************************************/
-
- struct VVRstruct {
- Int32 RecordSize; /* Size of current record (bytes) */
- Int32 RecordType; /* Type of record (ie. VVR) */
- void *buffer; /* Record(s) */
- };
-
- /*****************************************************************************
- * ADR structure.
- *****************************************************************************/
-
- struct ADRstruct {
- Int32 RecordSize; /* Size of current record (bytes) */
- Int32 RecordType; /* Type of record (ie. ADR) */
- Int32 ADRnext; /* File offset to next ADR (bytes) */
- Int32 AEDRhead; /* File offset to first AEDR (bytes) */
- Int32 Scope; /* variable or global */
- Int32 Num; /* Attribute Id Number */
- Int32 NumEntries; /* Number of attribute entries */
- Int32 MaxEntry; /* Maximum attribute entry number */
- Int32 rfuA; /* reserved for future use (value = 0) */
- Int32 rfuB; /* reserved for future use (value = 0) */
- Int32 rfuC; /* reserved for future use (value = 0) */
- Int32 rfuD; /* reserved for future use (value = -1) */
- Int32 rfuE; /* reserved for future use (value = -1) */
- char Name[CDF_ATTR_NAME_LEN+1];
- /* Attribute name */
- };
-
- /*****************************************************************************
- * AEDR structure.
- *****************************************************************************/
-
- struct AEDRstruct {
- Int32 RecordSize; /* Size of current record (bytes) */
- Int32 RecordType; /* Type of record (ie. AEDR) */
- Int32 AEDRnext; /* File offset to next AEDR */
- Int32 AttrNum; /* Attribute Id Number */
- Int32 DataType; /* Attribute Data Type */
- Int32 Num; /* Entry number (variable number or arbitrary global
- entry number) */
- Int32 NumElem; /* Number of elements of DataType */
- Int32 rfuA; /* reserved for future use (value = 0) */
- Int32 rfuB; /* reserved for future use (value = 0) */
- Int32 rfuC; /* reserved for future use (value = 0) */
- Int32 rfuD; /* reserved for future use (value = -1) */
- Int32 rfuE; /* reserved for future use (value = -1) */
- void *Value; /* Attribute Value */
- };
-
- /*****************************************************************************
- * Structure for variable index related data.
- *****************************************************************************/
-
- struct vixSTRUCT {
- struct vixSTRUCT *vixNext; /* pointer to next 'vix' */
- long VXRoffset; /* offset in file of VXR */
- struct VXRstruct VXR; /* VXR */
- };
-
- /*****************************************************************************
- * Structure for variable related data.
- *****************************************************************************/
-
- struct varSTRUCT {
- struct varSTRUCT *varNext;
- File *fp; /* For a MULTI file CDF, this is set when
- the variable file is first opened.
- For a SINGLE file CDF, this is set to the
- 'fp' of the CDF (the .CDF file contains
- the variable data) */
- long status;
- long NvalueBytes; /* number of bytes per value */
- long NphyRecValues; /* number of physical values per record */
- long NvirtRecValues; /* number of virtual values per record */
- long NphyRecBytes; /* number of physical bytes per record */
- long NvirtRecBytes; /* number of virtual bytes per record */
- long defaultNextendRecs; /* default number of records to extend when
- new allocations are necessary (only used
- if VDR doesn't contain number to use) */
- long *products;
- long *hypProducts;
- long *hypIndices;
- long *hypTops;
- long accessed_at;
- long seqValueOffset; /* Used for SEQUENTIAL ACCESS. The "current"
- value (not byte) offset. */
- long VDRoffset;
- struct VDRstruct VDR;
- struct vixSTRUCT *vixHead;
- struct vixSTRUCT *vixTail;
- };
-
- /*****************************************************************************
- * Structure for attribute entry related data.
- *****************************************************************************/
-
- struct entrySTRUCT {
- struct entrySTRUCT *entryNext;
- long AEDRoffset;
- struct AEDRstruct AEDR;
- };
-
- /*****************************************************************************
- * Structure for attribute related data.
- *****************************************************************************/
-
- struct attrSTRUCT {
- struct attrSTRUCT *attrNext;
- long ADRoffset;
- struct ADRstruct ADR;
- struct entrySTRUCT *entryHead;
- struct entrySTRUCT *entryTail;
- long V1dataType; /* used for V1.1 CDFs only (all
- entries had same data type) */
- long V1numBytes; /* used for V1.1 CDFs only */
- };
-
- /*****************************************************************************
- * Structure for CDF related data.
- *****************************************************************************/
-
- struct cdfSTRUCT {
- CDFid id;
- Int32 magic_number;
- char filename[CDF_FILE_NAME_LEN+1];
- File *fp;
- long status;
-
- long recnum;
- long reccount;
- long recinterval;
- long *indices;
- long *counts;
- long *intervals;
-
- long CDRoffset;
- struct CDRstruct CDR;
-
- long GDRoffset;
- struct GDRstruct GDR;
-
- struct attrSTRUCT *CURattr; /* current attribute */
- struct entrySTRUCT *CURentry; /* current entry (of the current attribute) */
- struct varSTRUCT *CURvar; /* current variable */
- long CURentryNum; /* currently selected entry number (a
- corresponding entry in the current
- attribute does not have to exist yet */
- struct varSTRUCT *varHead;
- struct varSTRUCT *varTail;
- struct varSTRUCT *var[CDF_MAX_VARS]; /* These are short cuts to the
- variable structures */
- struct attrSTRUCT *attrHead;
- struct attrSTRUCT *attrTail;
- };
-
- /******************************************************************************
- * Determine disposition of status. Note the 'return' statement if the status
- * is an error.
- *
- * For each call to the CDF library, status is returned as follows.
- *
- * 1. The first ERROR encountered terminates the call and is returned.
- * 2. The last WARNING encountered is returned. INFOs encountered after a
- * WARNING are ignored.
- * 3. In the absence of any WARNINGs, the last INFO is returned.
- * 4. In the absence of any WARNINGs or INFOs, CDF_OK is returned.
- *
- ******************************************************************************/
-
- #define STATUSdisp(Tstatus,Pstatus) { \
- STATUSdispX (Tstatus, &Pstatus); \
- if (Pstatus < CDF_WARN) return Pstatus; \
- }
-
- /******************************************************************************
- * Calculate byte offset to variable record if SINGLE file format.
- ******************************************************************************/
-
- #define SINGLErecOffsetB(Var,recNum,recOffset) { \
- struct vixSTRUCT *Vix = Var->vixHead; \
- long _i; \
- recOffset = -1; \
- for (;;) { \
- for (_i = 0; _i < Vix->VXR.NusedEntries; _i++) \
- if (Vix->VXR.FirstRec[_i] <= recNum && \
- recNum <= Vix->VXR.LastRec[_i]) { \
- recOffset = Vix->VXR.VVRoffset[_i] + VVR_BASE_SIZE + \
- Var->NphyRecBytes * (recNum - Vix->VXR.FirstRec[_i]); \
- break; \
- } \
- if (recOffset != -1) break; \
- Vix = Vix->vixNext; \
- if (Vix == NULL) break; \
- } \
- }
-
- /******************************************************************************
- * Calculate byte offset within variable record for given set of indices.
- ******************************************************************************/
-
- #define INDICESoffsetB(numDims,Var,indices,Boffset) { \
- long _dimN; \
- Boffset = 0; \
- for (_dimN = 0; _dimN < numDims; _dimN++) \
- if (Var->VDR.DimVarys[_dimN]) \
- Boffset += Var->products[_dimN] * indices[_dimN]; \
- Boffset *= Var->NvalueBytes; \
- }
-
- /******************************************************************************
- * Calculate value offset within variable record for given set of indices.
- ******************************************************************************/
-
- #define INDICESoffsetV(numDims,Var,indices,Voffset) { \
- long _dimN; \
- Voffset = 0; \
- for (_dimN = 0; _dimN < numDims; _dimN++) \
- if (Var->VDR.DimVarys[_dimN]) \
- Voffset += Var->products[_dimN] * indices[_dimN]; \
- }
-
- /******************************************************************************
- * Calculate indices for a value offset within variable record (Row major).
- ******************************************************************************/
-
- #define RowVoffsetINDICES(numDims,Var,Voffset,indices) { \
- long _VoffsetT = Voffset; \
- long _dimN; \
- for (_dimN = 0; _dimN < numDims; _dimN++) { \
- if (Var->VDR.DimVarys[_dimN]) { \
- indices[_dimN] = _VoffsetT / Var->products[_dimN]; \
- _VoffsetT = _VoffsetT % Var->products[_dimN]; \
- } \
- else \
- indices[_dimN] = 0; \
- } \
- }
-
- /******************************************************************************
- * Calculate indices for a value offset within variable record (Column major).
- ******************************************************************************/
-
- #define ColVoffsetINDICES(numDims,Var,Voffset,indices) { \
- long _VoffsetT = Voffset; \
- long _dimN; \
- for (_dimN = numDims - 1; _dimN >= 0; _dimN--) { \
- if (Var->VDR.DimVarys[_dimN]) { \
- indices[_dimN] = _VoffsetT / Var->products[_dimN]; \
- _VoffsetT = _VoffsetT % Var->products[_dimN]; \
- } \
- else \
- indices[_dimN] = 0; \
- } \
- }
-
- /******************************************************************************
- * Mark a record as unused.
- ******************************************************************************/
-
- #define WASTErecord(fp,offset,recordsize) { \
- long _RecordSize; \
- long _RecordType; \
- _RecordSize = recordsize; \
- _RecordType = UNUSED_; \
- Seek (fp, offset, SEEK_SET); \
- putint32 (fp, _RecordSize); \
- putint32 (fp, _RecordType); \
- }
-
- /******************************************************************************
- * Locate the previous variable on the linked list. Note that if the linked
- * list has been corrupted, the 'for (;;)' loop will continue until a NULL
- * pointer is used (not a good thing).
- ******************************************************************************/
-
- #define FINDprevVar(CDF,Var,prevVar) { \
- if (CDF->varHead == Var) \
- prevVar = NULL; \
- else { \
- prevVar = CDF->varHead; \
- for (;;) { \
- if (prevVar->varNext == Var) break; \
- prevVar = prevVar->varNext; \
- } \
- } \
- }
-
- /******************************************************************************
- * Locate the previous entry on the linked list. Note that if the linked
- * list has been corrupted, the 'for (;;)' loop will continue until a NULL
- * pointer is used (not a good thing).
- ******************************************************************************/
-
- #define FINDprevEntry(Attr,Entry,prevEntry) { \
- if (Attr->entryHead == Entry) \
- prevEntry = NULL; \
- else { \
- prevEntry = Attr->entryHead; \
- for (;;) { \
- if (prevEntry->entryNext == Entry) break; \
- prevEntry = prevEntry->entryNext; \
- } \
- } \
- }
-
- /******************************************************************************
- * MACRO to move C-style string to FORTRAN-style string.
- ******************************************************************************/
-
- #if defined(vms)
- #define CtoFORTstring(Cstring,FORTstring,defaultLen) { \
- char *_ptr; \
- size_t _len; \
- long _i; \
- if (! isDESCR(FORTstring,&_ptr,&_len)) { \
- _ptr = FORTstring; \
- _len = defaultLen; \
- } \
- strncpy (_ptr, Cstring, _len); \
- for (_i = strlen(Cstring); _i < _len; _i++) *(_ptr + _i) = ' '; \
- }
- #endif
-
- #if defined(unix)
- #define CtoFORTstring(Cstring,FORTstring,length) { \
- long _i; \
- strncpy (FORTstring, Cstring, length); \
- for (_i = strlen(Cstring); _i < length; _i++) FORTstring[_i] = ' '; \
- }
- #endif
-
- /******************************************************************************
- * Default fill values.
- ******************************************************************************/
-
- #if defined(CDFLIB)
- char _CDF_BYTEfv = { 0 };
- char _CDF_INT1fv = { 0 };
- short _CDF_INT2fv = { 0 };
- long _CDF_INT4fv = { 0 };
- unsigned char _CDF_UINT1fv = { 0 };
- unsigned short _CDF_UINT2fv = { 0 };
- unsigned long _CDF_UINT4fv = { 0 };
- float _CDF_REAL4fv = { 0.0 };
- double _CDF_REAL8fv = { 0.0 };
- float _CDF_FLOATfv = { 0.0 };
- double _CDF_DOUBLEfv = { 0.0 };
- double _CDF_EPOCHfv = { 0.0 };
- char _CDF_CHARfv = { ' ' };
- unsigned char _CDF_UCHARfv = { ' ' };
- #else
- extern char _CDF_BYTEfv;
- extern char _CDF_INT1fv;
- extern short _CDF_INT2fv;
- extern long _CDF_INT4fv;
- extern unsigned char _CDF_UINT1fv;
- extern unsigned short _CDF_UINT2fv;
- extern unsigned long _CDF_UINT4fv;
- extern float _CDF_REAL4fv;
- extern double _CDF_REAL8fv;
- extern float _CDF_FLOATfv;
- extern double _CDF_DOUBLEfv;
- extern double _CDF_EPOCHfv;
- extern char _CDF_CHARfv;
- extern unsigned char _CDF_UCHARfv;
- #endif
-
- #if defined(CDFLIB)
- void *_CDFdefaultFillValues[] =
- { NULL, (void *) &_CDF_INT1fv, (void *) &_CDF_INT2fv, NULL,
- (void *) &_CDF_INT4fv,
- NULL, NULL, NULL, NULL, NULL,
- NULL, (void *) &_CDF_UINT1fv, (void *) &_CDF_UINT2fv, NULL,
- (void *) &_CDF_UINT4fv,
- NULL, NULL, NULL, NULL, NULL,
- NULL, (void *) &_CDF_REAL4fv, (void *) &_CDF_REAL8fv, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL,
- NULL, (void *) &_CDF_EPOCHfv, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL,
- NULL, (void *) &_CDF_BYTEfv, NULL, NULL, (void *) &_CDF_FLOATfv,
- (void *) &_CDF_DOUBLEfv, NULL, NULL, NULL, NULL,
- NULL, (void *) &_CDF_CHARfv, (void *) &_CDF_UCHARfv, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL };
- #else
- extern void *_CDFdefaultFillValues[];
- #endif
-
- /******************************************************************************
- * Single element sizes (bytes) for each data type.
- ******************************************************************************/
-
- #if defined(CDFLIB)
- long _CDFelemSizes[] = {0,1,2,0,4,0,0,0,0,0,
- 0,1,2,0,4,0,0,0,0,0,
- 0,4,8,0,0,0,0,0,0,0,
- 0,8,0,0,0,0,0,0,0,0,
- 0,1,0,0,4,8,0,0,0,0,
- 0,1,1,0,0,0,0,0,0,0};
- #else
- extern long _CDFelemSizes[];
- #endif
-
- /******************************************************************************
- * "Equivalent" data types (if values are the same in this array).
- ******************************************************************************/
-
- #if defined(CDFLIB)
- long _CDFequivTypes[] = {0,1,2,0,3,0,0,0,0,0,
- 0,1,2,0,3,0,0,0,0,0,
- 0,4,5,0,0,0,0,0,0,0,
- 0,5,0,0,0,0,0,0,0,0,
- 0,1,0,0,4,5,0,0,0,0,
- 0,1,1,0,0,0,0,0,0,0};
- #else
- extern long _CDFequivTypes[];
- #endif
-
- /******************************************************************************
- * CDF copyright.
- ******************************************************************************/
-
- #if defined(CDFLIB)
- char _CDF_CopyRight[] =
- "\nNSSDC Common Data Format\n\
- (C) Copyright 1990,1991,1992 NASA/GSFC\n\
- National Space Science Data Center\n\
- NASA/Goddard Space Flight Center\n\
- Greenbelt, Maryland 20771 USA\n\
- (SPAN -- NSSDCA::CDFSUPPORT)\n\
- (Internet -- CDFSUPPORT@NSSDCA.GSFC.NASA.GOV)\n";
- #else
- extern char _CDF_CopyRight[];
- #endif
-
- /*****************************************************************************
- * CDF data. This array is indexed by CDFid. A value of NULL indicates that
- * the corresponding CDFid is available for use. Needless to say the number
- * of NULLs must agree with the value of CDF_MAX_CDFS.
- *****************************************************************************/
-
- #if defined(CDFLIB)
- struct cdfSTRUCT *_CDFs[CDF_MAX_CDFS] =
- { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
- #else
- extern struct cdfSTRUCT *_CDFs[];
- #endif
-
- /******************************************************************************
- * Encoding of host machine.
- ******************************************************************************/
-
- #if defined(CDFLIB)
- #if defined(sun)
- long _CDFhostEncoding = SUN_ENCODING;
- #endif
- #if defined(vax)
- long _CDFhostEncoding = VAX_ENCODING;
- #endif
- #if defined(MIPSEL)
- long _CDFhostEncoding = MIPSEL_ENCODING;
- #endif
- #if defined(MIPSEB)
- long _CDFhostEncoding = MIPSEB_ENCODING;
- #endif
- #if defined(__IBMPC__)
- long _CDFhostEncoding = IBMPC_ENCODING;
- #endif
- #if defined(IBMRS)
- long _CDFhostEncoding = IBMRS_ENCODING;
- #endif
- #if defined(HP)
- long _CDFhostEncoding = HP_ENCODING;
- #endif
- #else
- extern long _CDFhostEncoding;
- #endif
-
- /******************************************************************************
- * Miscellaneous variables.
- ******************************************************************************/
-
- #if defined(CDFLIB)
- struct cdfSTRUCT *_CURcdf = NULL;
- CDFstatus _CURstatus = RESERVED_CDFSTATUS;
- long _CDFpseudo_clock = 0;
- #else
- extern struct cdfSTRUCT *_CURcdf;
- extern CDFstatus _CURstatus;
- extern long _CDFpseudo_clock;
- #endif
-
- /******************************************************************************
- * Function prototypes.
- ******************************************************************************/
-
- #if defined(vms) | defined(__MSDOS__)
- void STATUSdispX (CDFstatus, CDFstatus *);
- int strcmpITB (char *, char *);
- void Free_CDFid (struct cdfSTRUCT *);
- CDFstatus CloseLRUvar (void);
- File *OpenFile (char *, char *);
- void calcVarParms (struct cdfSTRUCT *, struct varSTRUCT *);
- CDFstatus OpenVar (struct cdfSTRUCT *, struct varSTRUCT *);
- CDFstatus FillRecords (struct cdfSTRUCT *, struct varSTRUCT *, long, long);
- CDFstatus AllocateRecords (struct cdfSTRUCT *, struct varSTRUCT *, long,
- Boolean);
- void calc_V20_eof (struct cdfSTRUCT *);
- CDFstatus CloseCDFfiles (struct cdfSTRUCT *);
- CDFstatus ReopenCDFforWrite (struct cdfSTRUCT *);
-
- void incr_hypIndices_ROW (long *, long, long *, long *, long *, long *,
- Boolean *, Boolean *, long *);
- void incr_hypIndices_COL (long, long *, long, long *, long *, long *, long *,
- Boolean *, Boolean *, long *);
- CDFstatus HyperGetBytes (struct varSTRUCT *, long, long, void *);
- CDFstatus HyperPutBytes (struct varSTRUCT *, long, long, void *);
- CDFstatus HyperAccess (struct varSTRUCT *, void *, long, long);
-
- CDFstatus CDFcre (va_list *, long, long *);
- CDFstatus CDFope (va_list *, long, long *);
- CDFstatus CDFdel (long, long *);
- CDFstatus CDFclo (long, long *);
- CDFstatus CDFget (va_list *, long, long *);
- CDFstatus CDFput (va_list *, long, long *);
- CDFstatus CDFsel (va_list *, long, long *);
- CDFstatus CDFcon (va_list *, long, long *);
-
- #if defined(vms)
- CDFstatus read_V1_header (struct cdfSTRUCT *);
- #endif
-
- CDFstatus read_V2_header (struct cdfSTRUCT *);
- CDFstatus write_V2_header (struct cdfSTRUCT *);
-
- #if defined(vms)
- CDFstatus initializeCDFinfo (CDFid);
- CDFstatus inquireCDFinfo (CDFid, struct CDFinfoStruct *);
- void freeAttrInfo (struct attrInfoStruct *);
- CDFstatus putAttrInfo (CDFid, long, long, long);
- CDFstatus getAttrInfo (CDFid, long, long *, long *);
- #endif
-
- #if defined(vms)
- long CDFV2dataType (char *);
- CDFstatus CDFV1varNum (CDFid, void *, long *);
- CDFstatus CDFV1attrNum (CDFid, void *, long *);
- CDFstatus CDFV1attrEntryNum (CDFid, void *, long *);
- long CDFrcode (CDFstatus);
- void CDFV1_data_type (long, long, char *, long *);
- #endif
-
- char *NULterminate (char *, size_t);
-
- #if defined(vms)
- Boolean isDESCR (void *, char **, size_t *);
- char *DESCRtoREF (void *);
- char *DESCRtoREFnul (void *, size_t);
- #endif
-
- Boolean validCDFname (char *);
- Boolean validVarName (char *);
- Boolean validAttrName (char *);
- Boolean validDataType (long);
- Boolean validAttrScope (long);
- Boolean validEncoding (long, long *);
-
- void xdr_decode (long, long, void *);
- void xdr_encode (long, long, void *, void *);
-
- #if defined(__MSDOS__)
- long htonl (long);
- short htons (short);
- long ntohl (long);
- short ntohs (short);
- #endif
-
- #if defined(vms)
- int fix512 (char *);
- #endif
- #endif
-
-
- #if defined(unix)
- void STATUSdispX ();
- int strcmpITB ();
- void Free_CDFid ();
- CDFstatus CloseLRUvar ();
- File *OpenFile ();
- void calcVarParms ();
- CDFstatus OpenVar ();
- CDFstatus FillRecords ();
- CDFstatus AllocateRecords ();
- void calc_V20_eof ();
- CDFstatus CloseCDFfiles ();
- CDFstatus ReopenCDFforWrite ();
-
- void incr_hypIndices_ROW ();
- void incr_hypIndices_COL ();
- CDFstatus HyperGetBytes ();
- CDFstatus HyperPutBytes ();
- CDFstatus HyperAccess ();
-
- CDFstatus CDFcre ();
- CDFstatus CDFope ();
- CDFstatus CDFdel ();
- CDFstatus CDFclo ();
- CDFstatus CDFget ();
- CDFstatus CDFput ();
- CDFstatus CDFsel ();
- CDFstatus CDFcon ();
-
- #if 0
- CDFstatus read_V1_header ();
- #endif
-
- CDFstatus read_V2_header ();
- CDFstatus write_V2_header ();
-
- #if 0
- CDFstatus initializeCDFinfo ();
- CDFstatus inquireCDFinfo ();
- void freeAttrInfo ();
- CDFstatus putAttrInfo ();
- CDFstatus getAttrInfo ();
- #endif
-
- char *NULterminate ();
-
- #if 0
- Boolean isDESCR ();
- char *DESCRtoREF ();
- char *DESCRtoREFnul ();
- #endif
-
- Boolean validCDFname ();
- Boolean validVarName ();
- Boolean validAttrName ();
- Boolean validDataType ();
- Boolean validAttrScope ();
- Boolean validEncoding ();
-
- void xdr_decode ();
- void xdr_encode ();
-
- long htonl ();
- short htons ();
- long ntohl ();
- short ntohs ();
-
- #if 0
- int fix512 ();
- #endif
- #endif
-
- /*****************************************************************************/
-
- #endif /*___cdflib_h___*/
-